<div class='row-fluid'>
<div class='span9'>
<?php foreach ($queue as $k => $v) {?>
<?php
switch($v['status']) {
	case Controller_Queue::$status['to_send']:
		$color = '';
		$action = "<button class='cancel btn btn-mini btn-danger'>取消</button>";
		$action .= "&nbsp;<button class='edit btn btn-mini btn-primary'>编辑</button>";
		$status = '待发送';
		break;
	case Controller_Queue::$status['sent']:
		$color = 'alert-success';
		$action = "<button class='del btn btn-mini btn-danger'>删除</button>";
		$status = '已发送';
		break;
	case Controller_Queue::$status['failed']:
		$color = 'alert-error';
		$action = '';
		$status = '发送失败';
		//$action = "<button class='to_send btn btn-mini btn-success'>重发</button>";
		$action .= "&nbsp;<button class='edit btn btn-mini btn-primary'>编辑</button>";
		break;
	case Controller_Queue::$status['cancel']:
		$color = 'alert-info';
		$action = '';
		$status = '已取消';
		//$action = "<button class='to_send btn btn-mini btn-success'>重发</button>";
		$action .= "&nbsp;<button class='edit btn btn-mini btn-primary'>编辑</button>";
		break;
	case Controller_Queue::$status['del']:
		$color = 'alert-error';
		$action = '';
		$status = '已删除';
		//$action = "<button class='to_send btn btn-mini btn-success'>重发</button>";
		$action = "&nbsp;<button class='edit btn btn-mini btn-primary'>编辑</button>";
		break;
	default :
		$color = '';
		$action = '';
		break;
}
?>
<div class='alert span8 <?php echo $color;?>'>
	<div class='profile_image_url span1' >
		<img src='<?php echo $v["profile_image_url"]; ?>' width='50' height=50/>
		<p><?php echo $v['screen_name'];?></p>
	</div>
	<div class='text span6 msg' data-queue_id='<?php echo $v['id']; ?>' data-pic='<?php echo $v['image'];?>' data-content='<?php echo $v['text'];?>' data-screen_name='<?php echo $v['screen_name']; ?>'>
		<p class='text'><code><?php echo $status;?></code><?php echo $v['text']; ?></p>
		<?php if ($v['image'] != '') { $v['image'] = str_replace('/var/www/weibonian/public', '', $v['image']);?>
		<br />
		<a class="miniImg artZoom" href="<?php echo $v['image']; ?>" rel="<?php echo $v['image']; ?>" target="_blank"><img src="<?php echo $v['image']; ?>" width='80px'/></a>
		<?php }?>
		<div class='span6 offset1 links'>
			<ul>
				<li><?php echo "添加:{$v['created_at']}";?></li>
				<li><?php echo "发布:{$v['post_time']}";?></li>
				<?php 
	if ($v['post_id']){
		if (strstr($v['sina_user_idstr'], '.'))$v['sina_user_idstr'] = strstr($v['sina_user_idstr'], '.', true);
		if (strstr($v['post_id'], '.'))$v['post_id'] = strstr($v['post_id'], '.', true);
		echo "<li><a target='_blank' href='http://api.t.sina.com.cn/{$v['sina_user_idstr']}/statuses/{$v['post_id']}/' >链接</a></li>";
	}
				?>
				<li><?php echo $action;?></li>
				
			</ul>
		</div>
	</div>
</div>
<?php } ?>
</div>
<div class='span2'>
<div class='alert span2'>
	<a class="close" data-dismiss="alert">×</a>
	<strong>待发送</strong>
	<br />
	今:<?php echo $stat['to_send']['today']; ?>&nbsp;&nbsp;共:<?php echo $stat['to_send']['total']; ?>
</div>
<div class='alert alert-success span2'>
	<a class="close" data-dismiss="alert">×</a>
	<strong>已发送</strong>
	<br />
	今:<?php echo $stat['sent']['today'] + $stat['del']['today']; ?>&nbsp;&nbsp;共:<?php echo ($stat['sent']['total'] + $stat['del']['total']); ?>
</div>
<div class='alert alert-error span2'>
	<a class="close" data-dismiss="alert">×</a>
	<strong>发送失败</strong>
	<br />
	今:<?php echo $stat['failed']['today']; ?>&nbsp;&nbsp;共:<?php echo $stat['failed']['total']; ?>
</div>
<div class='alert alert-info span2'>
	<a class="close" data-dismiss="alert">×</a>
	<strong>取消</strong>
	<br />
	今:<?php echo $stat['cancel']['today']; ?>&nbsp;&nbsp;共:<?php echo $stat['cancel']['total']; ?>
</div>
<div class='alert alert-error span2'>
	<a class="close" data-dismiss="alert">×</a>
	<strong>删除</strong>
	<br />
	今:<?php echo $stat['del']['today']; ?>&nbsp;&nbsp;共:<?php echo $stat['del']['total']; ?>
</div>
</div>
</div>
<div class='offset0 pull-left'>
<?php echo html_entity_decode($page_links, ENT_QUOTES, 'UTF-8'); ?>
</div>
<script>
$('a.artZoom').artZoom();
$('.btn').button();
$('button.cancel').click(function() {
	$(this).button('loading');
	var that = $(this);
	var item = $(this).parent().parent().parent().parent().parent();
	var queue_id = $(this).parent().parent().parent().parent().attr('data-queue_id');
	$.post('/queue/action', {'action':'cancel', 'queue_id':queue_id}, function(r) {
		if (r.msg == 'succ') {
			alert('操作成功');
			item.addClass('alert-info');

			that.hide();
		} else {
			alert('操作失败');
		}
	}, 'json');
});
$('button.del').click(function() {
	$(this).button('loading');
	var that = $(this);
	var item = $(this).parent().parent().parent().parent().parent();
	var queue_id = $(this).parent().parent().parent().parent().attr('data-queue_id');
	$.post('/queue/action', {'action':'del', 'queue_id':queue_id}, function(r) {
		if (r.msg == 'succ') {
			alert('操作成功');
			item.addClass('alert-error');
			that.after('<span class="badge badge-success">已删除</span>');
			that.hide();
		} else {
			alert('操作失败');
		}
	}, 'json');
});

</script>
<style>
.links li{
float:left;
list-style:none;
padding:5px;
}
</style>
<div class="modal fade hide" id="myModal" style="padding-right:8px;">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>编辑微博</h3>
  </div>
  <div class="modal-body">
      <form class="form-horizontal" action='/queue/push' name='clone_push' id='clone_push'>
<div class="control-group">
<?php echo Form::textarea('description', '', array('rows' => 6, 'cols' => 20, 'class' => 'input-xxlarge')); ?>
</div>
<div class="control-group">
<?php $now = date('Y-m-d H:i', time() + 5*60 + 8*60*60);echo Form::input('post_time', $now, array('size' => 20, 'class' => 'input-large'));?>
</div>
<div class="alert alert-info">
选择上传则使用上传的图片代替原图片
</div>
<div class="control-group">
<?php echo Form::file('image',array('id' => 'image', 'class' => 'input-file'));?>
<input type='button' name='upload' class='btn' value='上传' onclick='ajaxFileUpload()'/>
</div>
<div class="control-group">
<select name='screen_name' id='screen_name'>
<?php foreach ($account as $k => $v) {?>
<option value='<?php echo $v['screen_name']; ?>'><?php echo $v['screen_name'];?></option>
<?}?>
</select>
</div>
<div class="control-group">
<?php echo Form::input('submit', '发送', array('id' => 'submit', 'type' => 'submit', 'class' => 'submit btn btn-success'));?>
</div>
      </form>
  </div>
</div>
<script>
var myModal = $('#myModal').html();
$('a.artZoom').artZoom();
$('.submit').button();
$('button.edit').click(function() {
	$('#myModal').html(myModal);
	$('input[name=post_time]').datetimepicker({
		'dateFormat': 'yy-mm-dd'
	});
	var that = $(this).parent().parent().parent().parent();
	pic = that.attr('data-pic');
	$('#clone_msg').hide();
	var sina_id = that.attr('data-sina-id');
	$('#myModal textarea').html(that.attr('data-content'));
	$('#myModal').modal('show');
	$('#image').val('');
	$('#clone_push').submit(function() {
		$('.submit').button('loading');
		var desc = $('textarea[name=description]').val();
		var post_time = $('input[name=post_time]').val();
		var screen_name = $('#screen_name').val();
		$.post('/queue/push_clone', {'screen_name': screen_name, 'image':pic, 'text': desc, 'post_time':post_time, 'sina_id':sina_id}, function(r) {
			if (r.msg == 'succ') {
				$('#clone_msg').html('操作成功');
			} else {
				$('#clone_msg').html('操作失败');
			}
			$('.submit').button('reset');
			alert('操作成功');
			window.location.reload();
			//$('#clone_msg').fadeIn('slow');
		}, 'json');
		return false;
	});
});
$('input[name=post_time]').datetimepicker({
'dateFormat': 'yy-mm-dd'
});
function ajaxFileUpload() {
	$.ajaxFileUpload({
		url:'/queue/upload',
		secureuri:false,
		fileElementId:'image',
		dataType: 'json',
		beforeSend:function(){
			$("#loading").show();
		},
		complete:function() {
			$("#loading").hide();
			},				
		success: function (data, status) {
			if(typeof(data.msg) != 'undefined') {
				if(data.msg != 'succ') {
					alert('上传失败');
				} else {
					pic = data.path;
					alert('上传成功');
				}
			}
		},
		error: function (data, status, e) {
			       alert(e);
		}
	});
	return false;
}
</script>
<style>
.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
.ui-timepicker-div dl { text-align: left; }
.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
.ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
</style>

